package com.cn.xiaonuo.slbfinances.slpabank.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.dbs.core.annotation.DataSource;
import com.cn.xiaonuo.slbfinances.slpabank.entity.SlPaDzOrder;
import com.cn.xiaonuo.slbfinances.slpabank.mapper.CmPaDzOrderMapper;
import com.cn.xiaonuo.slbfinances.slpabank.service.ICmPaDzOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CmPaDzOrderServiceImpl extends ServiceImpl<CmPaDzOrderMapper, String> implements ICmPaDzOrderService {
    @Resource
    private CmPaDzOrderMapper cmPaDzOrderMapper;

    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage querySlPaFzOrderList(Integer pageNo,
                                                Integer pageSize,
                                                String paychanneltranseqno,
                                                String shoppaymentid) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        if (null == pageSize || pageSize <= 0) {
            pageSize = 10;
        }
        if (null == pageNo || pageNo <= 0) {
            pageNo = 1;
        }
        // 设置分页参数
        PageHelper.startPage(pageNo, pageSize);
        List<Map<String, Object>> select = cmPaDzOrderMapper.querySlPaFzOrderList(paychanneltranseqno, shoppaymentid);
        PageInfo<List<SlPaDzOrder>> pageInfo = new PageInfo(select);
        if (select != null && select.size() >= 0) {
            message.setData(pageInfo);
            message.setMessage("查询成功");
            message.setCode("200");
            message.setSuccess(true);
            return message;
        }
        message.setData(pageInfo);
        message.setMessage("查询失败");
        message.setCode("-1");
        message.setSuccess(false);
        return message;
    }

    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage querySlDzList(Integer pageNo, Integer pageSize, SlPaDzOrder slPaDzOrder){
        BusinessMessage<Object> message = new BusinessMessage<>();
        if (null == pageSize || pageSize <= 0) {
            pageSize = 10;
        }
        if (null == pageNo || pageNo <= 0) {
            pageNo = 1;
        }
        // 设置分页参数
        PageHelper.startPage(pageNo, pageSize);
        List<SlPaDzOrder> select = cmPaDzOrderMapper.querySlPaDzOrderList(slPaDzOrder.getType(), slPaDzOrder.getTrNy());
        PageInfo<List<SlPaDzOrder>> pageInfo = new PageInfo(select);
        Map<String, Object> map = new HashMap<>();
        if (select != null && select.size() >= 0) {
            Double sumCommission = cmPaDzOrderMapper.sumCommission(slPaDzOrder.getType(), slPaDzOrder.getTrNy());
            Double sumTotalMoney = cmPaDzOrderMapper.sumTotalMoney(slPaDzOrder.getType(), slPaDzOrder.getTrNy());
            map.put("sumCommission", sumCommission);
            map.put("sumTotalMoney", sumTotalMoney);
            map.put("pageInfo", pageInfo);
            message.setData(map);
            message.setMessage("查询成功");
            message.setCode("200");
            message.setSuccess(true);
            return message;
        }
        message.setData(map);
        message.setMessage("查询失败");
        message.setCode("-1");
        message.setSuccess(false);
        return message;
    }


}
